const symbolDelayHideToast = Symbol('delayHideToast');

const prompt = {
  // toast
  // isShow: false,
  default_toastDuration: 5000,
  real_toastDuration: 0,
  real_timeout: null,

  // modal
  defalut_title: '提示',

  // 显示 Toast
  showToast (title, icon = 'none', config = {}) {
    const _this = this;
    // if (this.isShow === false) {
    wx.showToast({
      title,
      icon,
      duration: config.duration || _this.default_toastDuration,
      mask: false,
      ...config,
      complete () {
        // _this.isShow = true;
        _this.real_toastDuration = config.duration || _this.default_toastDuration;
        _this[symbolDelayHideToast]();
      }
    });
    // }
  },

  // 隐藏toast
  [symbolDelayHideToast] () {
    if (this.real_timeout) {
      clearTimeout(this.real_timeout);
    }
    this.real_timeout = setTimeout(() => {
      wx.hideToast();
    }, this.real_toastDuration);
  },

  // 显示模态对话框
  async showModal (content, config = {}) {
    const _this = this;
    return await wx.showModal({
      title: config.title || _this.defalut_title,
      content,
      showCancel: config.showCancel || false,
      cancelText: config.cancelText || '取消',
      cancelColor: config.cancelColor || '#000000',
      confirmText: config.confirmText || '确定',
      confirmColor: config.confirmColor || '#0080c6'
    });
  }
};

export default prompt;